readRes, err := sendRequest(config, "GET", project, url, userAgent, nil<%= object.error_retry_predicates ? ", " + object.error_retry_predicates.join(',') : "" -%>)
if err != nil {
	return handleNotFoundError(err, d, fmt.Sprintf("ComputeDisk %q", d.Id()))
}

// if disks are attached to instances, they must be detached before the disk can be deleted
if v, ok := readRes["users"].([]interface{}); ok {
	type detachArgs struct{ project, zone, instance, deviceName string }
	var detachCalls []detachArgs

	for _, instance := range convertStringArr(v) {
		self := d.Get("self_link").(string)
		instanceProject, instanceZone, instanceName, err := GetLocationalResourcePropertiesFromSelfLinkString(instance)
		if err != nil {
			return err
		}

		i, err := config.NewComputeClient(userAgent).Instances.Get(instanceProject, instanceZone, instanceName).Do()
		if err != nil {
			if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
				log.Printf("[WARN] instance %q not found, not bothering to detach disks", instance)
				continue
			}
			return fmt.Errorf("Error retrieving instance %s: %s", instance, err.Error())
		}
		for _, disk := range i.Disks {
			if compareSelfLinkOrResourceName("", disk.Source, self, nil) {
				detachCalls = append(detachCalls, detachArgs{
					project:    instanceProject,
					zone:       GetResourceNameFromSelfLink(i.Zone),
					instance:   i.Name,
					deviceName: disk.DeviceName,
				})
			}
		}
	}

	for _, call := range detachCalls {
		op, err := config.NewComputeClient(userAgent).Instances.DetachDisk(call.project, call.zone, call.instance, call.deviceName).Do()
		if err != nil {
			return fmt.Errorf("Error detaching disk %s from instance %s/%s/%s: %s", call.deviceName, call.project,
				call.zone, call.instance, err.Error())
		}
		err = computeOperationWaitTime(config, op, call.project,
			fmt.Sprintf("Detaching disk from %s/%s/%s", call.project, call.zone, call.instance), userAgent, d.Timeout(schema.TimeoutDelete))
		if err != nil {
			if opErr, ok := err.(ComputeOperationError); ok && len(opErr.Errors) == 1 && opErr.Errors[0].Code == "RESOURCE_NOT_FOUND" {
				log.Printf("[WARN] instance %q was deleted while awaiting detach", call.instance)
				continue
			}
			return err
		}
	}
}
